import mapview from './mapview';
import Vue from 'vue';
import store from '@/store';
import router from '@/router';
const MapConstructor = Vue.extend(mapview);
const Map = {
  /**
   * @param {*} isStart 起点或者终点
   * @param {*} type 拼车或者包车
   * @param {*} mode 站点、围栏、共存
   */
  createMap(isStart, type, mode = '1') {
    return new Promise((resolve, reject) => {
      let map = null;
      let params = {
        value: true,
        mode: mode,
        isStart: isStart,
        type: type
      };
      map = new MapConstructor({
        store,
        propsData: params
      }).$mount();
      if (map) {
        map.$on('close', () => {
          reject(new Error('cancel'));
          map.value = false;
          map.$destroy();
        });
        map.$on('confirm', () => {
          resolve();
          map.value = false;
          map.$destroy();
        });
        map.$on('gotoBaoService', () => {
          reject(new Error('bao'));
          map.value = false;
          map.$destroy();
        });
        map.$on('gotoPinService', () => {
          reject(new Error('pin'));
          map.value = false;
          map.$destroy();
        });
      }
    });
  }
};
export default Map;
